package org.taobao.ibatiside.ui.view;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.swt.widgets.Item;
import org.eclipse.ui.navigator.ICommonViewerMapper;
import org.taobao.ibatiside.core.filemodel.IbatisElement;
import org.taobao.ibatiside.core.filemodel.IbatisProject;

public class BatisCommonViewerMapper implements ICommonViewerMapper {
	private Map<Object, Item> mappings = new HashMap<Object, Item>();
	@Override
	public void addToMap(Object element, Item item) {
		mappings.put(element, item);
	}

	@Override
	public void removeFromMap(Object element, Item item) {
		mappings.remove(element);
	}

	@Override
	public void clearMap() {
		mappings.clear();
	}
	public Object getWrapper(IResource resource){
		if (resource == null) return null;
		for (Iterator<Object> iter = mappings.keySet().iterator(); iter.hasNext(); ){
			IbatisElement element = (IbatisElement) iter.next();
			if (resource.equals(element.getResource())){
				return element;
			}
		}
		return null;
	}
	@Override
	public boolean isEmpty() {
		return mappings.isEmpty();
	}

	@Override
	public boolean handlesObject(Object object) {
		return object instanceof IbatisElement;
	}

	@Override
	public void objectChanged(Object object) {
		
	}

}
